#include "appearance.h"
#include <QFile>
#include <QTranslator>

namespace HIM{
bool Appearance::LoadStyle(QApplication &app,QString qss_file)
{
    QFile file(qss_file);
    if(!file.open(QFile::ReadOnly))
    {
        throw AppearanceException("Open qss file failed.");
        return false;
    }
    QString styleSheet = QLatin1String(file.readAll());   
    app.setStyleSheet(styleSheet);
    return true;
}

bool Appearance::LoadTranslate(QApplication &app, QString trans_file)
{
    auto translator = new QTranslator;
    if(!translator->load(trans_file))
    {
        throw AppearanceException("Load translate file failed.");
        return false;
    }
    if(!app.installTranslator(translator))
    {
        throw AppearanceException("Apply translate file failed.");
        return false;
    }
    app.processEvents();
    return true;
}

}
